<link rel="stylesheet" href="__STATIC_LIB__layuiadmin/layui/layui_ext/dtree/dtree.css">
<link rel="stylesheet" href="__STATIC_LIB__layuiadmin/layui/layui_ext/dtree/font/dtreefont.css">

<form class="layui-form  seller-alone-form" id="userAdd" style="padding:20px;">

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label"><i class="required-color">*</i>教材名称：</label>
            <div class="layui-input-inline">
                <input type="text" name="book_name" required lay-verify="required" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label"><i class="required-color">*</i>教材单价：</label>
            <div class="layui-input-inline">
                <input type="text" name="book_price" required lay-verify="required" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label"><i class="required-color">*</i>折扣：</label>
            <div class="layui-input-inline">
                <input type="text" name="book_disc" required lay-verify="required" class="layui-input" value="0.85">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label"><i class="required-color">*</i>主编：</label>
            <div class="layui-input-inline">
                <input type="text" name="book_author" required lay-verify="required" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label"><i class="required-color">*</i>出版社：</label>
            <div class="layui-input-inline">
                <input type="text" name="book_concern" required lay-verify="required" class="layui-input">
            </div>
        </div>
    </div> 
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label"><i class="required-color">*</i>ISBN：</label>
            <div class="layui-input-inline">
                <input type="text" name="book_isbn" required lay-verify="required" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label"><i class="required-color">*</i>版次：</label>
            <div class="layui-input-inline">
                <input type="text" name="book_edition" required lay-verify="required" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label"><i class="required-color">*</i>出版年限：</label>
            <div class="layui-input-inline">
                <input type="text" name="book_date" required lay-verify="required" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">获奖情况：</label>
            <div class="layui-input-inline">
                <input type="text" name="book_reward" class="layui-input">
            </div>
        </div>
    </div>
    
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button id="user_add_save" class="layui-btn" lay-submit="" lay-filter="save">保存</button>
        </div>
    </div>
    {:zlserverToken()}
</form>
<script src="__STATIC_LIB__layuiadmin/layui/layui.js"></script>
<script>
    layui.extend({
        dtree: '__STATIC_LIB__layuiadmin/layui/layui_ext/dtree/dtree'
    }).use(['form', 'laydate', 'dtree'], function () { 
        var form = layui.form, laydate = layui.laydate, dtree = layui.dtree;
        form.render();
 
        //保存用户
        form.on('submit(save)', function(data){
            formData = data.field;
            if(!formData){
                layer.msg('请先完善数据', {time: 1300});
                return false;
            }
 
            // 判断单价：
            if(formData.book_price <= 0) {
                layer.msg('请输入合法的单价', { time: 1300 });
                return false;
            }

            // 判断折扣：
            if(formData.book_disc <= 0) {
                layer.msg('请输入正确的折扣信息', { time: 1300 });
                return false;
            }

            $("#user_add_save").addClass("layui-btn-disabled");
            $('#user_add_save').attr("disabled", true);

            $.ajax({
                type: 'post',
                url: '{:url("Book/addBookInfo")}',
                data: formData,
                dataType: 'json',
                success: function (e) { 
                    if(e.status === true){ 
                        layer.open({
                            type: 1
                            ,offset: 'auto'
                            ,id: 'layerDemoAuto'
                            ,content: '<div style="padding: 20px 100px;">'+ e.msg +'</div>'
                            ,btn: '关闭'
                            ,btnAlign: 'c' //按钮居中
                            ,shade: 0.3 //显示遮罩
                            ,yes: function(){
                                parent.layui.admin.events.changeTabAndRefresh('/manage/book/index.html', 'bookTable');
                            },close: function() {
                                console.log('close');
                            },end: function () {
                                parent.layui.admin.events.changeTabAndRefresh('/manage/book/index.html', 'bookTable');
                            }
                        });
                    }else{
                        $("#user_add_save").removeClass("layui-btn-disabled");
                        $('#user_add_save').removeAttr("disabled");

                        layer.msg(e.msg, {time: 1300});
                    }
                }
            });
            return false;
        });
    });
</script>
